##Copyright (C) 2012 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=test
PKG_RELEASE:=1

PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)
  SECTION:=utils
  CATEGORY:=User
  TITLE:=This is a test app
  DEPENDS:=+libncurses +libpthread +libuci
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./aliyun-iot-device-sdk-c-2017-01-24 $(PKG_BUILD_DIR)/
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Build/Configure
endef

SDK_DIR = ./aliyun-iot-device-sdk-c-2017-01-24

INCLUDE_DIRS = -I $(SDK_DIR)/include/ccp
INCLUDE_DIRS += -I $(SDK_DIR)/common/inc/
INCLUDE_DIRS += -I $(SDK_DIR)/platform/linux/inc/

CFLAGS = -g -Wall $(INCLUDE_DIRS)

LIB_DIRS = -L $(SDK_DIR)

LDFLAGS = $(LIB_DIRS) -liotsdk -lm -lpthread -luci

TARGET_LDFLAGS := $(LDFLAGS)

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
	CC="$(TARGET_CC)" \
	CFLAGS="$(TARGET_CFLAGS) -Wall" \
	LDFLAGS="$(LDFLAGS)"
endef

define Package/$(PKG_NAME)/install
	$(INSTALL_DIR) $(1)/usr/sbin/
	cp /home/song/work/source/openwrt15.05/openwrt/build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/uClibc-0.9.33.2/lib/libpthread.so.0 $(1)/usr/sbin/
#	cp /home/song/work/source/openwrt15.05/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/OpenWrt-SDK-ramips-mt7620_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/lib/libuci.so $(1)/usr/sbin/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,$(PKG_NAME)))

